package com.cls.business.mapper;

import com.cls.business.entity.Topic;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.cls.business.entity.TopicPlan;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * 课题 Mapper
 *
 * @author weimaomao
 * @date 2020-11-10 09:57:54
 */
@Repository
public interface TopicMapper extends BaseMapper<Topic> {

    @Select("SELECT * FROM biz_topic WHERE plan_id=#{planId} and is_delete=0 and topic_code is not null ")
    List<Topic> selectListByPlanId(@Param("planId") Long planId);

    /**
     * 魏起成
     * 根据planId查询已定级的数据用来生成课题编号
     *
     * @param planId
     * @return
     */
    @Select("SELECT * FROM biz_topic WHERE plan_id=#{planId} and is_delete=0 and topic_level_type is not null  order by topic_classify_code,topic_level_type ")
    List<Topic> selectHaveLevelListByPlanId(@Param("planId") Long planId);

    @Select("select plan.* from biz_topic_plan plan left join biz_topic topic on plan.plan_id=topic.plan_id where  topic.topic_id=#{topicId} and plan.is_delete=0 and topic.is_delete=0")
    TopicPlan selectPlanByTopicId(@Param("topicId") Long topicId);


    @Select("select * from biz_topic_plan where  is_delete=0 and topic_classify_code=#{classifyCode} ")
    List<TopicPlan> findTopicByClassifyCodeAndNoLevel(String classifyCode);

    /**
     * 魏起成 根据classifyCode  statusCode 与 未定级数量=0   查询计划
     *
     * @return
     */
    @Select("select * from biz_topic_plan plan\n" +
            "where is_delete=0 \n" +
            "and (select count(*) from biz_declare_topic where is_delete=0 and plan_id=plan.plan_id and final_level_type_code is null)=0\n" +
            "and\n" +
            "status_code=#{statusCode} \n" +
            "and topic_classify_code=#{classifyCode} ")
    List<TopicPlan> selectNoLevelByClassifyCodeAndStatusCode(@Param("classifyCode") String classifyCode, @Param("statusCode") String statusCode);



}
